<template>
  <div class="Header">
    <div class="logo">
      <h1>logo</h1>
    </div>
    <div class="Header_left">
      <!-- 展开闭合左边导航栏 -->
      <FoldMenu />
      <!-- 面包屑导航 -->
      <Breadcrumb />
    </div>
    <div class="Header_right">
      <el-autocomplete
        class="inline-input"
        v-model="searchPage.search_text"
        :fetch-suggestions="searchPage.querySearch"
        placeholder="请输入页面名称"
        :trigger-on-focus="false"
        @select="searchPage.handleSelect"
      >
        <template #suffix>
          <el-icon :size="18">
            <Search />
          </el-icon>
        </template>
      </el-autocomplete>

      <div class="icon" @click="$route.path != '/news' && $router.push('/news')">
        <el-tooltip class="item" effect="dark" content="消息提示" placement="bottom">
          <el-badge is-dot class="item">
            <el-icon :size="20">
              <ChatLineRound />
            </el-icon>
          </el-badge>
        </el-tooltip>
      </div>
      <div class="icon" @click="fullScreen">
        <el-tooltip class="item" effect="dark" content="全屏" placement="bottom">
          <el-icon :size="20">
            <Rank />
          </el-icon>
        </el-tooltip>
      </div>
      <!-- 右上角头像 -->
      <el-dropdown @command="logout">
        <div class="el-dropdown-link">
          <img src="@/assets/logo.svg" />
          <span>admni</span>
          <el-icon>
            <ArrowDown :size="20" />
          </el-icon>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item icon="plus" command="黄金糕">黄金糕</el-dropdown-item>
            <el-dropdown-item icon="circle-plus" command="狮子头">狮子头</el-dropdown-item>
            <el-dropdown-item icon="circle-plus" command="螺蛳粉">螺蛳粉</el-dropdown-item>
            <el-dropdown-item icon="check" command="双皮奶">双皮奶</el-dropdown-item>
            <el-dropdown-item icon="circle-check" command="蚵仔煎">蚵仔煎</el-dropdown-item>
            <el-dropdown-item icon="back" command="退出登录">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts">
import Breadcrumb from './Breadcrumb.vue'
import FoldMenu from '../FoldMenu.vue'
import { useMainStore } from "@/stores/main"
import useSearchPageHook from "./hooks/useSearchPageHook"
import useFullScreenHook from "./hooks/useFullScreenHook"
import { reactive, ref, toRef, toRefs, getCurrentInstance } from 'vue'
import { useRouter } from 'vue-router'
export default {
  components: {
    Breadcrumb, FoldMenu
  },
  setup() {

    const $router = useRouter()
    const { proxy } = getCurrentInstance() as AnyObject

    function logout(type: string) {
      if (type === "退出登录") {
        sessionStorage.removeItem("access_token");
        $router.push({ path: "/login" });
      }else{
        proxy.$message.error(`没有${type}了, 大胖子`)
      }
    }
    return {
      logout,
      store: useMainStore(),
      searchPage: useSearchPageHook(),
      ...useFullScreenHook()
    }
  }
}
</script>

<style lang="scss" scoped>
.Header {
  display: flex;
  align-items: center;
  height: 100%;
  // box-shadow: 2px -1px 3px -2px #000000 inset !important;
  .logo {
    width: 200px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  &_left {
    display: flex;
    align-items: center;
    .el-breadcrumb {
      margin-left: 5px;
      flex-shrink: 0;
    }
    .FoldMenu {
      margin-right: 10px;
    }
  }
  &_right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 20px;
    padding-left: 20px;
    :deep(.inline-input) {
      margin-right: 15px;
      .el-input__wrapper {
        border-radius: 16px;
      }
    }
    :deep(.icon) {
      margin-right: 15px;
      height: 20px;
      cursor: pointer;
    }

    .el-dropdown {
      &-link {
        display: flex;
        align-items: center;
        img {
          width: 40px;
          height: 40px;
          border-radius: 5px;
          display: block;
          margin-right: 6px;
        }
      }
    }
  }
}
</style>